#include "ChainTest.hh"

ResultOf ChainTest::testBasicCase(Chain* List)
{
	ResultOf Result;
	Result = List->addHeader((void*)1);
	checkErrorWR(Result, "Fail List->addHeader.");
	
	Result = List->addHeader((void*)2);
	checkErrorWR(Result, "Fail List->addHeader.");
	
	Result = List->addHeader((void*)3);
	checkErrorWR(Result, "Fail List->addHeader.");
	
	if (List->tellSize() != 3)
	{
		notifyError(List->tellSize(), "Counting is not correct.");
		return RETURN_ERROR;
	}
	
	if ((Number)List->removeHeader() != 3)
	{
		notifyError(3, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}
	
	if ((Number)List->removeHeader() != 2)
	{
		notifyError(3, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}
	
	if ((Number)List->removeHeader() != 1)
	{
		notifyError(3, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}
	
	if (List->tellSize() != 0)
	{
		notifyError(List->tellSize(), "Not exiting completely.");
		return RETURN_ERROR;
	}
	
	Result = List->addTail((void*)1);
	checkErrorWR(Result, "Fail List->addTail.");
	
	Result = List->addTail((void*)2);
	checkErrorWR(Result, "Fail List->addTail.");
	
	Result = List->addTail((void*)3);
	checkErrorWR(Result, "Fail List->addTail.");
	
	if (List->tellSize() != 3)
	{
		notifyError(List->tellSize(), "Counting is not correct.");
		return RETURN_ERROR;
	}
	
	if ((Number)List->removeTail() != 3)
	{
		notifyError(3, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}
	
	if ((Number)List->removeTail() != 2)
	{
		notifyError(3, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}
	
	if ((Number)List->removeTail() != 1)
	{
		notifyError(3, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}
	
	if (List->tellSize() != 0)
	{
		notifyError(List->tellSize(), "Not exiting completely.");
		return RETURN_ERROR;
	}
	
	return RETURN_OK;
}

ResultOf ChainTest::testBasicCase2(Chain* List)
{
	ResultOf Result;
	Result = List->addHeader((void*)1);
	checkErrorWR(Result, "Fail List->addHeader.");
	
	Result = List->addHeader((void*)2);
	checkErrorWR(Result, "Fail List->addHeader.");
	
	Result = List->addHeader((void*)3);
	checkErrorWR(Result, "Fail List->addHeader.");
	
	if (List->tellSize() != 3)
	{
		notifyError(List->tellSize(), "Counting is not correct.");
		return RETURN_ERROR;
	}
	
	if ((Number)List->removeTail() != 1)
	{
		notifyError(3, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}
	
	if ((Number)List->removeTail() != 2)
	{
		notifyError(3, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}
	
	if ((Number)List->removeTail() != 3)
	{
		notifyError(3, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}
	
	if (List->tellSize() != 0)
	{
		notifyError(List->tellSize(), "Not exiting completely.");
		return RETURN_ERROR;
	}
	
	Result = List->addTail((void*)1);
	checkErrorWR(Result, "Fail List->addTail.");
	
	Result = List->addTail((void*)2);
	checkErrorWR(Result, "Fail List->addTail.");
	
	Result = List->addTail((void*)3);
	checkErrorWR(Result, "Fail List->addTail.");
	
	if (List->tellSize() != 3)
	{
		notifyError(List->tellSize(), "Counting is not correct.");
		return RETURN_ERROR;
	}
	
	if ((Number)List->removeHeader() != 1)
	{
		notifyError(3, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}
	
	if ((Number)List->removeHeader() != 2)
	{
		notifyError(3, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}
	
	if ((Number)List->removeHeader() != 3)
	{
		notifyError(3, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}
	
	if (List->tellSize() != 0)
	{
		notifyError(List->tellSize(), "Not exiting completely.");
		return RETURN_ERROR;
	}
	
	return RETURN_OK;
}

ResultOf ChainTest::testBasicCase3(Chain* List)
{
	ResultOf Result;
	Result = List->addHeader((void*)3);
	checkErrorWR(Result, "Fail List->addHeader.");
	
	Result = List->addHeader((void*)2);
	checkErrorWR(Result, "Fail List->addHeader.");
	
	Result = List->addTail((void*)4);
	checkErrorWR(Result, "Fail List->addTail.");
  
	Result = List->addTail((void*)5);
	checkErrorWR(Result, "Fail List->addTail.");

	Result = List->addTail((void*)6);
	checkErrorWR(Result, "Fail List->addTail.");
	
	Result = List->addHeader((void*)1);
	checkErrorWR(Result, "Fail List->addHeader.");
	
	if (List->tellSize() != 6)
	{
		notifyError(List->tellSize(), "Counting is not correct.");
		return RETURN_ERROR;
	}
	
	if ((Number)List->removeHeader() != 1)
	{
		notifyError(1, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}

	if ((Number)List->removeHeader() != 2)
	{
	notifyError(2, "The resulting value is incorrect.");
	return RETURN_ERROR;
	}

	if ((Number)List->removeTail() != 6)
	{
		notifyError(6, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}

	if ((Number)List->removeTail() != 5)
	{
		notifyError(5, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}

	if ((Number)List->removeHeader() != 3)
	{
		notifyError(3, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}

	if ((Number)List->removeTail() != 4)
	{
		notifyError(4, "The resulting value is incorrect.");
		return RETURN_ERROR;
	}

	if (List->tellSize() != 0)
	{
		notifyError(-1, "Not exiting completely.");
		return RETURN_ERROR;
	}

	return RETURN_OK;
}

ResultOf testChain()
{
	Chain List;
	ChainTest Test;
	ResultOf Result;
	
	Result = Test.testBasicCase(&List);
	checkErrorWR(Result, "Fail Test.testBasicCase.");
	
	Result = Test.testBasicCase2(&List);
	checkErrorWR(Result, "Fail Test.testBasicCase2.");
	
	Result = Test.testBasicCase3(&List);
	checkErrorWR(Result, "Fail Test.testBasicCase3.");
	
	fprintf(stderr, "Chain: Test success.\n");
	return RETURN_OK;
}
